package com.huiyujinrong.qiangdanbao.model;


import com.huiyujinrong.qiangdanbao.network.AppService;
import com.huiyujinrong.qiangdanbao.utils.RequestInterceptor;

import java.io.File;

import javax.inject.Inject;

import happyloan.core.EventBusUtil;
import happyloan.core.RespBase;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;

public class FeedbackModel {

    private AppService service;

    private MultipartBody.Part mp_a;
    private MultipartBody.Part mp_b;
    private MultipartBody.Part mp_c;
    private MultipartBody.Part mp_d;

    @Inject
    FeedbackModel(AppService service) {
        this.service = service;
    }

    public void upLoadFeedback(String user_id, String feedback_content, File image_a, File image_b, File image_c, File image_d) {

        if(image_a!=null) {
            mp_a = MultipartBody.Part.createFormData("photo_files", "", RequestBody.create(MediaType.parse("image/*"), image_a));
        }else {
            mp_a=null;
        }
        if(image_b!=null) {
            mp_b = MultipartBody.Part.createFormData("photo_files", "", RequestBody.create(MediaType.parse("image/*"), image_b));
        }else {
            mp_b=null;
        }
        if(image_c!=null) {
            mp_c = MultipartBody.Part.createFormData("photo_files", "", RequestBody.create(MediaType.parse("image/*"), image_c));
        }else {
            mp_c=null;
        }
        if(image_d!=null) {
            mp_d = MultipartBody.Part.createFormData("photo_files", "", RequestBody.create(MediaType.parse("image/*"), image_d));
        }else {
            mp_d=null;
        }

        RequestBody UserId = RequestBody.create(MediaType.parse("text/plain"), user_id);
        RequestBody FeedbackContent = RequestBody.create(MediaType.parse("text/plain"), feedback_content);

        RequestInterceptor.outSign = true;
        RequestInterceptor.extraMap.put("user_id", user_id);
        RequestInterceptor.extraMap.put("feedback_content", feedback_content);

        Call<RespBase<String>> call = service.upLoadFeedBack(UserId, FeedbackContent, mp_a, mp_b, mp_c, mp_d);

        EventBusUtil<String> util = new EventBusUtil<>();
        util.sendEvent4Call(call);
    }
}
